<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:tpa81map="http://www.robot-electronics.co.uk/2006/10/tpa81map.html"
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      TPA81 Map Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      TPA81 Map Service
    </xsl:variable>
    <xsl:variable name="description">
      This is a scan of 32 servo positions across by eight pixels up of the TPA81 infra red heat sensor.
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />

        <style type="text/css">
          /* Service-specific stylesheet goes here */

          td.Pixel {width:10px; height: 10px; vertical-align: top; color: #F37913; font-size: 11px;  font-weight: bold; }

        </style>
        <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */

dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->
 	<xsl:template match="/tpa81map:TPA81MapState">

				<div class="RightColumn">
					<span class="SubTitle">
						<xsl:value-of select="count(tpa81map:SphericalMaps/*)" /> map
						<xsl:if test="count(tpa81map:SphericalMaps/*) &gt; 1">s</xsl:if>
						found
					</span>
				</div>
				<br clear="all"/>
				<xsl:for-each select="tpa81map:SphericalMaps/*">
					<div class="Module">
						<span class="ModuleName">
								TPA81 at I2C Address <xsl:value-of select="tpa81map:I2CAddress"/>
						</span>
						<br />
						<span class="SmallText">
							Last contact: <xsl:value-of select="tpa81map:LastContact"/>
						</span>
						<br/>
						<br/>
						
						<span class="key">MaxTemp: </span>
						<span class="value">
							<xsl:value-of select="tpa81map:MaxTemp"/>
						</span> 
						<br/>
					
						<span class="key">Pixel: </span>
						<span class="value">
							<xsl:value-of select="tpa81map:MaxTempHPos"/>, <xsl:value-of select="tpa81map:MaxTempVPos"/>
						</span>
						<br/>
					
						<span class="key">Angle: </span>
						<span class="value">
							<xsl:value-of select="tpa81map:MaxTempHAngle"/>, <xsl:value-of select="tpa81map:MaxTempVAngle"/>
						</span>
						<br/>

						<span class="key">Servo Range: </span>
						<span class="value">
							<xsl:value-of select="tpa81map:ServoRange"/>
						</span>
						<br/>
						<span class="key">Ambient Temperature: </span>
						<span class="value">
							<xsl:value-of select="tpa81map:AmbientTemperature"/>
						</span>
						<xsl:variable name="Ambient" select="number(tpa81map:AmbientTemperature)"/>
						<table class="Pixels">
							<xsl:for-each select="tpa81map:PolarMaps/*">
									<tr>
										<xsl:for-each select="tpa81map:Readings/*">
											<xsl:variable name="ambDif" select="number(.) - number($Ambient)" />
										<td class="Pixel">
											<xsl:attribute name="style">
												<xsl:text>background-color: rgb(</xsl:text>
												<xsl:choose>
													<xsl:when test="(number(.) &gt; 26) and (number(.) &lt; 33) and (number(.) &gt; number($Ambient))">
														<xsl:text>100,</xsl:text><xsl:value-of select="100 + ((number(.)-25)*15)" /><xsl:text>,100</xsl:text>
													</xsl:when>
													<xsl:otherwise>
														<xsl:choose>
															<xsl:when test="$ambDif &gt; 0">
																<xsl:value-of select="100 + ($ambDif*3)" /><xsl:text>,100,100</xsl:text>
															</xsl:when>
															<xsl:otherwise>
																<xsl:text>100,100,</xsl:text><xsl:value-of select="100 + ($ambDif*3)" />
															</xsl:otherwise>
														</xsl:choose>
													</xsl:otherwise>
												</xsl:choose>
												
												<xsl:text>)</xsl:text>
											</xsl:attribute>
										</td>
									</xsl:for-each>
								</tr>
							</xsl:for-each>
						</table>
						
					</div>
				</xsl:for-each>
				<br/>
				<div class="hr"></div>
				<div class="RightColumn">
					<a class="LinkSmall" href="http://www.robot-electronics.co.uk/htm/tpa81tech.htm">View Devantech documentation</a>
				</div>
				Use the <a href="/tpa81hardware">tpa81hardware</a> page for configuration.
	</xsl:template>

</xsl:stylesheet>
